package com.aurora.source.authority.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.authority.activity.ExamineActivity;
import com.aurora.source.authority.bean.PersonAuthBean;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;
import com.aurora.source.util.ErrorImgUtil;
import com.aurora.source.widget.CircleImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author: ww
 * @description:
 * @date: 2018/9/10
 */
public class PersonAuthAdapter extends BaseRecyclerAdapter<PersonAuthBean.UserInfoDTOListBean> {

    private List<PersonAuthBean.UserInfoDTOListBean> data = new ArrayList<>();
    private OnRegistClick onDeleteClick;
    private OnAuthClick onAuthClick;

    public void setOnAuthClick(OnAuthClick onAuthClick) {
        this.onAuthClick = onAuthClick;
    }

    public void setOnDeleteClick(OnRegistClick onDeleteClick) {
        this.onDeleteClick = onDeleteClick;
    }

    public interface OnRegistClick {
        void onRegistClick(PersonAuthBean.UserInfoDTOListBean data, int position);
    }

    public interface OnAuthClick{
        void onAuthClick(PersonAuthBean.UserInfoDTOListBean data, int position);
    }

    @Override
    public CommonHolder<PersonAuthBean.UserInfoDTOListBean> setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent, R.layout.item_person_auth);
    }

    class MyHolder extends CommonHolder<PersonAuthBean.UserInfoDTOListBean> {
        @BindView(R.id.iv_head)
        CircleImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_slash)
        TextView tvSlash;
        @BindView(R.id.tv_auth)
        TextView tvAuth;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_nickname)
        TextView tvNickname;
        @BindView(R.id.tv_examine)
        TextView tvExamine;
        @BindView(R.id.tv_accredit)
        TextView tvAccredit;
        @BindView(R.id.tv_cancelled)
        TextView tvCancelled;
        Context context;

        public MyHolder(Context context, ViewGroup root, int layoutRes) {
            super(context, root, layoutRes);
            this.context = context;
        }

        @Override
        public void bindData(final PersonAuthBean.UserInfoDTOListBean personAuthBean, final int position) {
            if(personAuthBean.getUserStatus().equals("SUCCESS")){
                tvCancelled.setText("冻结"); //点击冻结
            }else {
                tvCancelled.setText("解冻"); //点击减冻
            }
            tvExamine.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getContext(), ExamineActivity.class);
                    intent.putExtra("userId",personAuthBean.getUserId());
                    context.startActivity(intent);
                }
            });
            tvCancelled.setOnClickListener(new View.OnClickListener() { //注销
                @Override
                public void onClick(View v) {
                    if(onDeleteClick!=null){
                        onDeleteClick.onRegistClick(personAuthBean, position);
                    }
                }
            });
            tvAccredit.setOnClickListener(new View.OnClickListener() { //授权
                @Override
                public void onClick(View v) {
                    if(onAuthClick!=null){
                        onAuthClick.onAuthClick(personAuthBean, position);
                    }
                }
            });
            Glide.with(context)
                    .load(personAuthBean.getUserHeadPath())
                    .apply(new RequestOptions().placeholder(R.drawable.ico_txiang01))
                    .into(ivHead);
            tvName.setText(personAuthBean.getUserAccount());
            tvNickname.setText(personAuthBean.getUserName());
            tvAuth.setText(personAuthBean.getProcessTitles());
            tvTime.setText(personAuthBean.getCreateTime());
        }


    }


}
